<?php
/**
 * 
 * Form Create Category
 * @package Form
 * @filesource /application/forms/CreateCategory.php
 * @author Windy
 *
 */
class Form_CreateCategory extends Zend_Form
{
	private $formDecorators;
	private $elementDecorators;
	private $buttonDecorators;
	private $hiddenDecorators;
	
	/**
	 * 
	 * Constructor set id and class for form
	 * @param string $id
	 * @param string $class
	 */
	
    
    public function __construct($id= "", $class = "")
    {
    	$this->setAttrib('accept-charset', 'utf-8');
    	
    	$this->formDecorators = array(
    								array('FormElements'),
    								array('Form',array("name"=>$id, "class"=>$class))
    							);
    						
    	$this->elementDecorators = array(
    									array('Label', array()), 
    									array("HTMLTag",array("tag"=>"div","class"=>"row")),
    									array("Description",array("tag"=>"span"))
    								);
    	$this->buttonDecorators = array(
										array('ViewHelper'),
										array("HTMLTag",array("tag"=>"div","class"=>"buttons"))
										
									);
									
		$this->hiddenDecorators = array(
    									
    									array("HTMLTag",array("tag"=>"div")),
    									array("Description",array("tag"=>"span"))
    								);					
    	//add decorator for form
        $this->addDecorators($this->formDecorators);
        $this->setName('frmAECategory');
        
        
        $stringLength = new Zend_Validate_StringLength(4);
        $stringLength->setMessage(
        	'Tên chuyên mục phải có ít nhất %min% kí tự',
    		Zend_Validate_StringLength::TOO_SHORT
    	);
        
    		$txtName = $this->createElement("text", "name")
        				->setLabel("Tiêu đề:")
        				->setRequired(TRUE)
        				->setAttrib("size", 30)
        				->setValidators(array(new Zend_Validate_StringLength(array(8,15))))
        				->addDecorators($this->elementDecorators);
        	$this->addElement($txtName);
    	//add slug
    	$txtSlug = $this->createElement('text', 'slug')
    					->setLabel("Slug (tên hiển thị trên URL):")
    					->setRequired(TRUE)
    					->setAttrib("size", 30)
    					->setValidators(array(new Zend_Validate_Regex('/[a-z0-9-]*/')))
    					->addDecorators($this->elementDecorators);
    	$this->addElement($txtSlug);
    	
		//add textarea name='description'
		$taDescription = $this->createElement('textarea', 'description')
							  ->setLabel('Miêu tả')
							  ->addDecorators($this->elementDecorators);
							 
		$this->addElement($taDescription);
    	//add submit
    	$btnSubmit = $this->createElement('submit', 'submit')
    					->setLabel('Lưu')
    					->setOptions(array('class'=>'button'))
    					->addDecorators($this->buttonDecorators);
        $this->addElement($btnSubmit);
        //add reset
        $btnReset = $this->createElement('reset', 'reset')
    					->setLabel('Làm lại')
    					->setOptions(array('class'=>'button'))
    					->addDecorators($this->buttonDecorators);
        $this->addElement($btnReset);
    }
//    /**
//     * (non-PHPdoc)
//     * @see Zend_Form::populate()
//     */
//    public function populate($values, $arrActivedLanguages){
//    	
//    	parent::populate($values);
//    	//điền giá trị vào các trường name
//    	foreach($arrActivedLanguages as $language){
//    		$name = $this->getElement($language->code.'_name');
//    		$name->setValue(Helper_HtmlRender::getTextByLanguage($values['name'], $language->code));
//    	}
//    	$hddID = $this->createElement('hidden', 'id')
//    					->setValue($values['id'])
//    					->addDecorators($this->hiddenDecorators);
//    	$this->addElement($hddID);
//    	
//    	
//    }
}
?>